﻿/*	@file	r_math_vector2.h
	@brief	2次元ベクトル
Copyright (c) 2009 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_MATH_VECTOR2_H_
#define _R_MATH_VECTOR2_H_

#include "r_math_def.h"

namespace r{
	namespace math{
		//! インターフェースを実装する
		struct Vector2D {
		public:
			//! コンストラクタ
			Vector2D();
			Vector2D ( r_f32 sx, r_f32 sy );
			Vector2D ( const r_f32 *sv );
		public:
			//! 比較
			r_bool		operator == ( const Vector2D &src ) const;
			//! 加算
			Vector2D	operator + ( const Vector2D &src ) const;
			//! 減算
			Vector2D	operator - ( const Vector2D &src ) const;
			//! 乗算
			Vector2D	operator * ( const Vector2D &src ) const;
			//! 乗算
			/*! 各要素をsrcで乗算します
			*/
			Vector2D	operator * ( const r_f32 &src ) const;
			//! 除算
			Vector2D	operator / ( const Vector2D &src ) const;
			//! 除算
			/*! 各要素をsrcで除算します
			*/
			Vector2D	operator / ( const r_f32 &src ) const;
			///
			Vector2D&	operator += ( const Vector2D &src );
			///
			Vector2D&	operator -= ( const Vector2D &src );
			///
			Vector2D&	operator *= ( const Vector2D &src );
			///
			Vector2D&	operator /= ( const Vector2D &src );
			///
			Vector2D&	operator *= ( const r_f32 &src );
			///
			Vector2D&	operator /= ( const r_f32 &src );
		public:
			//! ベクトルの内積を取得
			r_f32		dot ( const Vector2D &src ) const;
			//! ベクトルの外積を取得
			r_f32		cross ( const Vector2D &src ) const;
			//! ベクトルの長さを取得
			r_f32		length ( void ) const;
			//! ベクトルの長さの二乗を取得
			r_f32		lengthsq ( void ) const;
			//! ベクトルの正規化
			void		normalize ( void );
			//! 正規化ベクトルの計算
			Vector2D	normal ( void ) const;
			//! ゼロ初期化
			void		zero ( void );
		public:
			union {
				struct {
					r_f32		x;
					r_f32		y;
				};
				r_f32			v[2];
			};
		};
	}
}
#include "../rtti/r_rtti_reflection_typename.h"
namespace r{
	namespace rtti{
		//! r::math::Vector2D
		template<>
		static inline
		const r_cstr	getTypeNameStr<r::math::Vector2D>() {
			return _RST ( "r::math::Vector2D" );
		}
	}
}

#endif // _R_MATH_VECTOR2_H_
